package com.ruoyi.project.basic.inventory.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.basic.inventory.domain.JcInventory;
import com.ruoyi.project.basic.inventory.service.IJcInventoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 存货档案Controller
 * 
 * @author frank
 * @date 2024-08-24
 */
@RestController
@RequestMapping("/basic/inventory/inventory")
public class JcInventoryController extends BaseController
{
    @Autowired
    private IJcInventoryService jcInventoryService;

    /**
     * 查询存货档案列表
     */
    @PreAuthorize("@ss.hasPermi('basic/inventory:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcInventory jcInventory)
    {
        startPage();
        List<JcInventory> list = jcInventoryService.selectJcInventoryList(jcInventory);
        return getDataTable(list);
    }

    /**
     * 导出存货档案列表
     */
    @PreAuthorize("@ss.hasPermi('basic/inventory:inventory:export')")
    @Log(title = "存货档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcInventory jcInventory)
    {
        List<JcInventory> list = jcInventoryService.selectJcInventoryList(jcInventory);
        ExcelUtil<JcInventory> util = new ExcelUtil<JcInventory>(JcInventory.class);
        util.exportExcel(response, list, "存货档案数据");
    }

    /**
     * 获取存货档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic/inventory:inventory:query')")
    @GetMapping(value = "/{jcInventoryoid}")
    public AjaxResult getInfo(@PathVariable("jcInventoryoid") String jcInventoryoid)
    {
        return success(jcInventoryService.selectJcInventoryByJcInventoryoid(jcInventoryoid));
    }

    /**
     * 新增存货档案
     */
    @PreAuthorize("@ss.hasPermi('basic/inventory:inventory:add')")
    @Log(title = "存货档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcInventory jcInventory)
    {
        return toAjax(jcInventoryService.insertJcInventory(jcInventory));
    }

    /**
     * 修改存货档案
     */
    @PreAuthorize("@ss.hasPermi('basic/inventory:inventory:edit')")
    @Log(title = "存货档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcInventory jcInventory)
    {
        return toAjax(jcInventoryService.updateJcInventory(jcInventory));
    }

    /**
     * 删除存货档案
     */
    @PreAuthorize("@ss.hasPermi('basic/inventory:inventory:remove')")
    @Log(title = "存货档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jcInventoryoids}")
    public AjaxResult remove(@PathVariable String[] jcInventoryoids)
    {
        return toAjax(jcInventoryService.deleteJcInventoryByJcInventoryoids(jcInventoryoids));
    }
}
